package com.fhz.core_lib.interceptor;

import com.fhz.core_lib.utils.SPUtils;

import java.io.IOException;

import okhttp3.HttpUrl;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

/**
 * 时间:2021/11/25
 *
 * @author msfeng
 * 简述: token拦截器
 */
public class TokenInterceptor implements Interceptor {
    @Override
    public Response intercept(Chain chain) throws IOException {
        Request original = chain.request();
        //根据不盘的url 判断是不是要加入token
//        HttpUrl url = original.url(); //base he api
        String token = SPUtils.getInstance().getString(SPUtils.TOKEN, "");
        Request.Builder requestBuilder = original.newBuilder()
                .header("Authorization", token);
        Request request = requestBuilder.build();
        return chain.proceed(request);
    }
}
